<?php
declare (strict_types = 1);
namespace app\index\model\car;

use think\Model;

/**
 * @mixin \think\Model
 */
class CarModel extends Model
{
    protected $pk = "id";

    /**
     * 获取信息
     * @param $where
     * @return array|null|Model
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    function getInfoByWhere($where){
        return $this->where($where)->find();
    }

    /**
     * 获取列表
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    function getList($where=[],$field="*"){
        $getList = $this->where($where)->field($field)->select();
        if($getList){
            $getList = $getList->toArray();
            foreach ($getList as $key=>$value){
                if(!$value['model_img']) $getList[$key]['model_img'] = config('add.web_url')."/static/imgs/carImage.png";
            }
            return $getList;
        }else{
            return [];
        }
    }

}
